<script>
	let socket = null;
	import Vue from 'vue'
	export default {
		onLaunch: function() {	
			//检查更新
			const updateManger = uni.getUpdateManager();
			updateManger.onCheckForUpdate(function(res) {
				if(res.hasUpdate){
					updateManger.onUpdateReady(function(){
						uni.showModal({
							title:"更新提示",
							content:"新版本已经准备好，是否重启应用？",
							success: (r) => {
							   if(r.confirm){
								   updateManger.applyUpdate();
								   
							   }	
							}
						})
					});
					updateManger.onUpdateFailed(function(){
						uni.showModal({
							title:"已经有新版本了哟~",
							content:"新版本已经上线啦~，请您删除当前小程序，重新打开"							
						})
					})
				}
			})
			uni.hideTabBar();
			//获取系统的基本信息
			uni.getSystemInfo({
				success: function(e) {
					Vue.prototype.WH = e.screenHeight;
					Vue.prototype.WW = e.screenWidth;
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		
					Vue.prototype.bodtyH = e.windowHeight - e.statusBarHeight;
				}
			});
			//连接通讯
			let heartbeat = {
				heartbeat: ""
			}
			setInterval(() => {
				uni.sendSocketMessage({
					data: JSON.stringify(heartbeat),
					success: res => {
						// console.log("消息通知监听到事件来自 :数据发成功" + JSON.stringify(res))
					},
					fail: e => {

					}
				})
			}, 55000);
			this.createSocket();
		},
		onShow: function() {
			// console.log("或从后台进入前台显示");
		},
		onHide: function() {
			// console.log("从前台进入后台")

		},
		methods: {
			/**
			 * 创建通信连接
			 */
			createSocket() {
				uni.connectSocket({
					url: "wss://xy.icefxy.com:3848",
					header: {
						'content-type': 'application/json',
					},
					method: 'GET',
					success: (res) => {
						this.onopen();
					},
					fail: (e) => {
						setTimeout(() => {
							this.createSocket();
						}, 3000)
					}
				})
			},
			/**
			 * 创建连接回调执行
			 */
			onopen() {
				let authorization = uni.getStorageSync('authorization');
				let dat = {
					'authorization': authorization
				}
				uni.onSocketOpen((res) => {
					uni.sendSocketMessage({
						data: JSON.stringify(dat),
						success: res => {

						},
						fail: e => {

						}
					})
					uni.onSocketMessage((res) => {
						let dat = JSON.parse(res.data);
						if (dat.code == 200) {
							uni.$emit('notice', {
								msg: '消息通知',
								code: 200,
								data: dat.data
							})

						}
					})
				})
				uni.onSocketError((res) => {
					setTimeout(() => {
						this.createSocket();
					}, 1000)

				});


			}



		}
	}
</script>
<style>
	@import "./static/css/main.css";
	@import "./static/font/iconfont.css";

	[v-cloak] {
		display: none !important;
	}
     
	/**外卖中的通用样式**/

	.page-body {
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background-color: #F7F7F7;
	}

	.red-color {
		color: #fe4646;
	}
	.padding-right-0{
		padding-right: 0 !important;
	}

	.gray-color {
		color: #999999;
	}

	.blue-color {
		color: #1270e0;
	}

	.edit-ico {
		width: 34upx;
		height: 34upx;
	}

	.del-ico {
		width: 34upx;
		height: 34upx;
	}

	.setting-ico {
		width: 40rpx;
		height: 40rpx;
	}

	* {
		padding: 0;
		margin: 0;
		line-height: 1.2;
		font-family: sans-serif;
	}

	.titilestyle {
		font-size: 40rpx;
	}

	.text-blod {
		font-weight: 600;
	}

	.pages {
		width: 100vw;
		height: 99.5vh;
		overflow-x: hidden;

	}

	.html {
		height: 99vh;
		overflow: hidden;
		background-color: #F7F7F7;
	}

	.pointer-evernt {
		pointer-events: none;
	}

	.content {
		width: 100vw;
		display: flex;
		flex-direction: column;

	}

	.middle {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.boxes {
		position: relative;
		width: 100%;
		height: 96vh;
		display: flex;
		justify-content: center;
	}

	.loading-box {
		width: 100vw;
		height: 100vh;
		position: absolute;
		z-index: 98;
		top: 0;
		left: 0;
		background-color: #FFFFFF;
	}

	.titilestyle {
		font-weight: 550;
		font-size: 35upx;
		display: block;
		white-space: nowrap;
		align-items: center;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.border {
		border: 1px solid red;
	}

	.backicon {
		height: 100%;
		display: flex;
		align-items: center;
		margin-left: 1vw;
		margin-right: 1vw;
		font-size: 45upx;

	}

	.head-title {
		height: 100%;
		display: flex;
		align-items: center;
	}

	.scrollEnd {
		width: 100%;
		height: 200upx;
	}

	.foot {
		width: 100vw;
		height: 200upx;
		background-color: transparent;
	}


	/**
	 * 顶部搜索
	 */
	.search-box1 {
		width: 100vw;
		display: flex;
		flex-direction: row;
		background: #FFFFFF;

	}

	.input-search-box {
		width: 60%;
		height: 86%;
		display: flex;
		align-items: center;
		background: #F7F7F7;
		border-radius: 20px;
		position: relative;
	}

	.inputSearch {
		width: 80%;
		height: 100%;
		padding-left: 5%;

	}

	.iconsousuo {
		color: #FF999999;
		font-size: 45upx;
		position: absolute;
		float: right;
		right: 2%;
		z-index: 9;
	}

	.mescroll-upwarp {
		margin-bottom: 100upx;
	}



	.fade-in {
		-webkit-animation: fade-in 1s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
		animation: fade-in 1s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
	}

	@-webkit-keyframes fade-in {
		0% {
			opacity: 0;
		}

		100% {
			opacity: 1;
		}
	}

	@keyframes fade-in {
		0% {
			opacity: 0;
		}

		100% {
			opacity: 1;
		}
	}
</style>
